package com.gd.common.util;

import java.util.ArrayList;

import android.content.Context;
import android.database.DataSetObserver;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gd.common.entities.C_Message;
import com.gd.main.R;
public class MessageAdapter  extends BaseAdapter {
	 private static final String TAG = MessageAdapter.class.getSimpleName();

	    private ArrayList<C_Message> coll;

	    private Context ctx;

	    public MessageAdapter(Context context, ArrayList<C_Message> coll) {
	    	 System.out.println("Talkffffffffffffffffff");
	    	ctx = context;
	        this.coll = coll;
	    }

	    public boolean areAllItemsEnabled() {
	        return false;
	    }

	    public boolean isEnabled(int arg0) {
	        return false;
	    }

	    public int getCount() {
	    	 System.out.println("Talk____Count_START");
	    	return coll.size();
	    	
	    }

	    public Object getItem(int position) {
	    	 System.out.println("Talk____GETITEM_START");
	    	return coll.get(position);
	    }

	    public long getItemId(int position) {
	    	 System.out.println("Talk____Count_GETITEMID");
	        return position;
	    }

	    public int getItemViewType(int position) {
	    	 System.out.println("Talk____Count_GETITEMVIEW_TYPE");
	        return position;
	    }

	    public View getView(int position, View convertView, ViewGroup parent) {
	    	 System.out.println("Talk_____VIEWSTART:Position:"+position);
	        C_Message entity = coll.get(position);
	        
	        String timeString = String.valueOf(entity.getTime());
	        
	        System.out.println("C_Message:"+entity.getFrom_userid()+","+entity.getTo_user_id()+","
	        		+entity.getMessage()+", "+entity.getTime());
	        int itemLayout = entity.getLayoutID();
	        System.out.println("Talk_____VIEW_END1");
	       
	        LinearLayout layout = new LinearLayout(ctx);
	        LayoutInflater vi = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	        vi.inflate(itemLayout, layout, true);

	        System.out.println("Talk_____VIEW_END2");
	        TextView to_userid = (TextView) layout.findViewById(R.id.messagedetail_row_name);
	        to_userid.setText("mearo");
	        System.out.println("Talk_____VIEW_END3");
	        TextView time = (TextView) layout.findViewById(R.id.messagedetail_row_date);
	        time.setText(timeString);
	        System.out.println("Talk_____VIEW_END4");
	        TextView message = (TextView) layout.findViewById(R.id.messagedetail_row_text);
	        message.setText(entity.getMessage());
	        System.out.println("Talk_____VIEW_END");
	        return layout;
	    }

	    public int getViewTypeCount() {
	    	 System.out.println("Talk____GETVIEWTYPE_COUNT");
	        return coll.size();
	    }

	    public boolean hasStableIds() {
	    	 System.out.println("Talk____STABLE_ID");
	        return false;
	    }

	    public boolean isEmpty() {
	    	 System.out.println("Talk____ISEMPTY");
	        return false;
	    }

	    public void registerDataSetObserver(DataSetObserver observer) {
	    }

	    public void unregisterDataSetObserver(DataSetObserver observer) {
	    }
	}
